package com.hedl.practice.diyJava;

public class JavaAndStringBuilder {
    public static void main(String[] args) {

/*        StringBuilder sb = new StringBuilder(1024);
        for (int i = 0; i < 1000; i++){
            sb.append(',');
            sb.append(i);
        }
        String s = sb.toString();;
        System.out.println(s);*/

/*        //字符串链式操作
        StringBuilder sb = new StringBuilder(1024);
        sb.append("Mr ")
                .append("Bob")
                .append("!")
                .insert(0,"Hello, ");
        System.out.println(sb.toString());*/

/*        //测试计数类
        Adder adder = new Adder();
        adder.add(3)
                .add(5)
                .inc()
                .add(10);
        System.out.println(adder.value());*/


        String[] fields = {"name","position","salary"};
        String table = "employee";
        String insert = buildInsertSql(table,fields);
        System.out.println(insert);
        String s = "INSERT INTO employee (name, position, salary) VALUES (?, ?, ?)";
        System.out.println(s.equals(insert)?"测试成功！":"测试失败！");

    }
    static String buildInsertSql(String tables,String[] fields){
        //TODO:
        StringBuilder sb = new StringBuilder(1024);
        sb.append("INSERT INTO ")
                .append(tables+" (")
                .append(String.join(", ",fields))
                .append(") "+"VALUES"+" (")
                .append(String.join(", ",fields).replaceAll("\\w+","?"))
                .append(")");
        return sb.toString();
    }
}
